12#ifndef AOM_AV1_COMMON_AV1_COMMON_INT_H_
13#define AOM_AV1_COMMON_AV1_COMMON_INT_H_
17#include "config/aom_config.h"
18#include "config/av1_rtcd.h"
20#include "aom/internal/aom_codec_internal.h"
21#include "aom_dsp/flow_estimation/corner_detect.h"
22#include "aom_util/aom_pthread.h"
23#include "av1/common/alloccommon.h"
24#include "av1/common/av1_loopfilter.h"
25#include "av1/common/entropy.h"
26#include "av1/common/entropymode.h"
27#include "av1/common/entropymv.h"
29#include "av1/common/frame_buffers.h"
30#include "av1/common/mv.h"
31#include "av1/common/quant_common.h"
33#include "av1/common/tile_common.h"
34#include "av1/common/timing.h"
35#include "aom_dsp/grain_params.h"
36#include "aom_dsp/grain_table.h"
37#include "aom_dsp/odintrin.h"
42#if defined(__clang__) && defined(__has_warning)
43#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
44#define AOM_FALLTHROUGH_INTENDED [[clang::fallthrough]]
46#elif defined(__GNUC__) && __GNUC__ >= 7
47#define AOM_FALLTHROUGH_INTENDED __attribute__((fallthrough))
50#ifndef AOM_FALLTHROUGH_INTENDED
51#define AOM_FALLTHROUGH_INTENDED \
56#define CDEF_MAX_STRENGTHS 16
59#define FRAME_ID_LENGTH 15
60#define DELTA_FRAME_ID_LENGTH 14
62#define FRAME_CONTEXTS (FRAME_BUFFERS + 1)
64#define FRAME_CONTEXT_DEFAULTS (FRAME_CONTEXTS - 1)
65#define PRIMARY_REF_BITS 3
66#define PRIMARY_REF_NONE 7
68#define NUM_PING_PONG_BUFFERS 2
70#define MAX_NUM_TEMPORAL_LAYERS 8
71#define MAX_NUM_SPATIAL_LAYERS 4
75#define MAX_NUM_OPERATING_POINTS \
76 (MAX_NUM_TEMPORAL_LAYERS * MAX_NUM_SPATIAL_LAYERS)
81#define TXCOEFF_TIMER 0
82#define TXCOEFF_COST_TIMER 0
88 COMPOUND_REFERENCE = 1,
89 REFERENCE_MODE_SELECT = 2,
91} UENUM1BYTE(REFERENCE_MODE);
97 REFRESH_FRAME_CONTEXT_DISABLED,
102 REFRESH_FRAME_CONTEXT_BACKWARD,
103} UENUM1BYTE(REFRESH_FRAME_CONTEXT_MODE);
105#define MFMV_STACK_SIZE 3
108 uint8_t ref_frame_offset;
113 MV_REFERENCE_FRAME ref_frame;
116typedef struct RefCntBuffer {
131 unsigned int order_hint;
132 unsigned int ref_order_hints[INTER_REFS_PER_FRAME];
138 unsigned int display_order_hint;
139 unsigned int ref_display_order_hint[INTER_REFS_PER_FRAME];
141 unsigned int pyramid_level;
145 struct segmentation seg;
152 WarpedMotionParams global_motion[REF_FRAMES];
154 uint8_t film_grain_params_present;
155 aom_film_grain_t film_grain_params;
157 YV12_BUFFER_CONFIG buf;
160 FRAME_TYPE frame_type;
164 int interp_filter_selected[SWITCHABLE];
167 int8_t ref_deltas[REF_FRAMES];
170 int8_t mode_deltas[MAX_MODE_LF_DELTAS];
172 FRAME_CONTEXT frame_context;
177typedef struct BufferPool {
183#if CONFIG_MULTITHREAD
184 pthread_mutex_t pool_mutex;
193 RefCntBuffer *frame_bufs;
194 uint8_t num_frame_bufs;
197 InternalFrameBufferList int_frame_buffers;
235 int delta_q_present_flag;
238 int delta_lf_present_flag;
248 int enable_order_hint;
249 int order_hint_bits_minus_1;
253 int enable_dist_wtd_comp;
255 int enable_ref_frame_mvs;
265typedef struct SequenceHeader {
269 int max_frame_height;
274 uint8_t frame_id_numbers_present_flag;
276 int delta_frame_id_length;
281 OrderHintInfo order_hint_info;
283 uint8_t force_screen_content_tools;
286 uint8_t still_picture;
287 uint8_t reduced_still_picture_hdr;
288 uint8_t force_integer_mv;
291 uint8_t enable_filter_intra;
292 uint8_t enable_intra_edge_filter;
293 uint8_t enable_interintra_compound;
294 uint8_t enable_masked_compound;
295 uint8_t enable_dual_filter;
297 uint8_t enable_warped_motion;
299 uint8_t enable_superres;
304 uint8_t enable_restoration;
305 BITSTREAM_PROFILE profile;
310 uint8_t use_highbitdepth;
319 uint8_t separate_uv_delta_q;
320 uint8_t film_grain_params_present;
323 int operating_points_cnt_minus_1;
324 int operating_point_idc[MAX_NUM_OPERATING_POINTS];
327 bool has_nonzero_operating_point_idc;
328 int timing_info_present;
329 aom_timing_info_t timing_info;
330 uint8_t decoder_model_info_present_flag;
331 aom_dec_model_info_t decoder_model_info;
332 uint8_t display_model_info_present_flag;
333 AV1_LEVEL seq_level_idx[MAX_NUM_OPERATING_POINTS];
334 uint8_t tier[MAX_NUM_OPERATING_POINTS];
339 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1];
343 int skip_mode_allowed;
350 FRAME_TYPE frame_type;
351 REFERENCE_MODE reference_mode;
353 unsigned int order_hint;
354 unsigned int display_order_hint;
356 unsigned int pyramid_level;
357 unsigned int frame_number;
358 SkipModeInfo skip_mode_info;
359 int refresh_frame_flags;
360 int frame_refs_short_signaling;
611 int height, BLOCK_SIZE min_partition_size);
680 const qm_val_t *
giqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
684 const qm_val_t *
gqmatrix[NUM_QM_LEVELS][3][TX_SIZES_ALL];
774 struct aom_internal_error_info *
error;
928#if CONFIG_ENTROPY_STATS
932 int coef_cdf_category;
955 struct loopfilter
lf;
1068 int64_t cum_txcoeff_timer;
1069 int64_t txcoeff_timer;
1073#if TXCOEFF_COST_TIMER
1074 int64_t cum_txcoeff_cost_timer;
1075 int64_t txcoeff_cost_timer;
1076 int64_t txcoeff_cost_count;
1084static void lock_buffer_pool(BufferPool *
const pool) {
1085#if CONFIG_MULTITHREAD
1086 pthread_mutex_lock(&pool->pool_mutex);
1092static void unlock_buffer_pool(BufferPool *
const pool) {
1093#if CONFIG_MULTITHREAD
1094 pthread_mutex_unlock(&pool->pool_mutex);
1100static inline YV12_BUFFER_CONFIG *get_ref_frame(AV1_COMMON *cm,
int index) {
1101 if (index < 0 || index >= REF_FRAMES)
return NULL;
1106static inline int get_free_fb(AV1_COMMON *cm) {
1107 RefCntBuffer *
const frame_bufs = cm->
buffer_pool->frame_bufs;
1111 const int num_frame_bufs = cm->
buffer_pool->num_frame_bufs;
1112 for (i = 0; i < num_frame_bufs; ++i)
1113 if (frame_bufs[i].ref_count == 0)
break;
1115 if (i != num_frame_bufs) {
1116 if (frame_bufs[i].buf.use_external_reference_buffers) {
1120 YV12_BUFFER_CONFIG *ybf = &frame_bufs[i].buf;
1121 ybf->y_buffer = ybf->store_buf_adr[0];
1122 ybf->u_buffer = ybf->store_buf_adr[1];
1123 ybf->v_buffer = ybf->store_buf_adr[2];
1124 ybf->use_external_reference_buffers = 0;
1127 frame_bufs[i].ref_count = 1;
1131 assert(0 &&
"Ran out of free frame buffers. Likely a reference leak.");
1140static inline RefCntBuffer *assign_cur_frame_new_fb(AV1_COMMON *
const cm) {
1148 const int new_fb_idx = get_free_fb(cm);
1149 if (new_fb_idx == INVALID_IDX)
return NULL;
1152#if CONFIG_AV1_ENCODER && !CONFIG_REALTIME_ONLY
1153 aom_invalidate_pyramid(cm->
cur_frame->buf.y_pyramid);
1154 av1_invalidate_corner_list(cm->
cur_frame->buf.corners);
1156 av1_zero(cm->
cur_frame->interp_filter_selected);
1162static inline void assign_frame_buffer_p(RefCntBuffer **lhs_ptr,
1163 RefCntBuffer *rhs_ptr) {
1164 RefCntBuffer *
const old_ptr = *lhs_ptr;
1165 if (old_ptr != NULL) {
1166 assert(old_ptr->ref_count > 0);
1168 --old_ptr->ref_count;
1173 ++rhs_ptr->ref_count;
1176static inline int frame_is_intra_only(
const AV1_COMMON *
const cm) {
1181static inline int frame_is_sframe(
const AV1_COMMON *cm) {
1188static inline int get_ref_frame_map_idx(
const AV1_COMMON *
const cm,
1189 const MV_REFERENCE_FRAME ref_frame) {
1190 return (ref_frame >= LAST_FRAME && ref_frame <= EXTREF_FRAME)
1195static inline RefCntBuffer *get_ref_frame_buf(
1196 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1197 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1198 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1203static inline const struct scale_factors *get_ref_scale_factors_const(
1204 const AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1205 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1209static inline struct scale_factors *get_ref_scale_factors(
1210 AV1_COMMON *
const cm,
const MV_REFERENCE_FRAME ref_frame) {
1211 const int map_idx = get_ref_frame_map_idx(cm, ref_frame);
1215static inline RefCntBuffer *get_primary_ref_frame_buf(
1216 const AV1_COMMON *
const cm) {
1218 if (primary_ref_frame == PRIMARY_REF_NONE)
return NULL;
1219 const int map_idx = get_ref_frame_map_idx(cm, primary_ref_frame + 1);
1220 return (map_idx != INVALID_IDX) ? cm->
ref_frame_map[map_idx] : NULL;
1224static inline int frame_might_allow_ref_frame_mvs(
const AV1_COMMON *cm) {
1226 cm->
seq_params->order_hint_info.enable_ref_frame_mvs &&
1227 cm->
seq_params->order_hint_info.enable_order_hint &&
1228 !frame_is_intra_only(cm);
1232static inline int frame_might_allow_warped_motion(
const AV1_COMMON *cm) {
1237static inline void ensure_mv_buffer(RefCntBuffer *buf, AV1_COMMON *cm) {
1238 const int buf_rows = buf->mi_rows;
1239 const int buf_cols = buf->mi_cols;
1242 if (buf->mvs == NULL || buf_rows != mi_params->
mi_rows ||
1243 buf_cols != mi_params->
mi_cols) {
1245 buf->mi_rows = mi_params->
mi_rows;
1246 buf->mi_cols = mi_params->
mi_cols;
1247 CHECK_MEM_ERROR(cm, buf->mvs,
1248 (MV_REF *)aom_calloc(((mi_params->
mi_rows + 1) >> 1) *
1249 ((mi_params->
mi_cols + 1) >> 1),
1250 sizeof(*buf->mvs)));
1251 aom_free(buf->seg_map);
1255 sizeof(*buf->seg_map)));
1258 const int mem_size =
1263 CHECK_MEM_ERROR(cm, cm->
tpl_mvs,
1264 (TPL_MV_REF *)aom_calloc(mem_size,
sizeof(*cm->
tpl_mvs)));
1269#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
1270void cfl_init(CFL_CTX *cfl,
const SequenceHeader *seq_params);
1273static inline int av1_num_planes(
const AV1_COMMON *cm) {
1274 return cm->
seq_params->monochrome ? 1 : MAX_MB_PLANE;
1277static inline void av1_init_above_context(
CommonContexts *above_contexts,
1278 int num_planes,
int tile_row,
1280 for (
int i = 0; i < num_planes; ++i) {
1287static inline void av1_init_macroblockd(AV1_COMMON *cm, MACROBLOCKD *xd) {
1288 const int num_planes = av1_num_planes(cm);
1291 for (
int i = 0; i < num_planes; ++i) {
1292 if (xd->
plane[i].plane_type == PLANE_TYPE_Y) {
1314#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
1319static inline void set_entropy_context(MACROBLOCKD *xd,
int mi_row,
int mi_col,
1320 const int num_planes) {
1322 int row_offset = mi_row;
1323 int col_offset = mi_col;
1324 for (i = 0; i < num_planes; ++i) {
1325 struct macroblockd_plane *
const pd = &xd->
plane[i];
1327 const BLOCK_SIZE bsize = xd->
mi[0]->
bsize;
1328 if (pd->subsampling_y && (mi_row & 0x01) && (mi_size_high[bsize] == 1))
1329 row_offset = mi_row - 1;
1330 if (pd->subsampling_x && (mi_col & 0x01) && (mi_size_wide[bsize] == 1))
1331 col_offset = mi_col - 1;
1332 int above_idx = col_offset;
1333 int left_idx = row_offset & MAX_MIB_MASK;
1334 pd->above_entropy_context =
1336 pd->left_entropy_context =
1341static inline int calc_mi_size(
int len) {
1343 return ALIGN_POWER_OF_TWO(len, MAX_MIB_SIZE_LOG2);
1346static inline void set_plane_n4(MACROBLOCKD *
const xd,
int bw,
int bh,
1347 const int num_planes) {
1349 for (i = 0; i < num_planes; i++) {
1350 xd->
plane[i].width = (bw * MI_SIZE) >> xd->
plane[i].subsampling_x;
1351 xd->
plane[i].height = (bh * MI_SIZE) >> xd->
plane[i].subsampling_y;
1353 xd->
plane[i].width = AOMMAX(xd->
plane[i].width, 4);
1354 xd->
plane[i].height = AOMMAX(xd->
plane[i].height, 4);
1358static inline void set_mi_row_col(MACROBLOCKD *xd,
const TileInfo *
const tile,
1359 int mi_row,
int bh,
int mi_col,
int bw,
1360 int mi_rows,
int mi_cols) {
1372 const int ss_x = xd->
plane[1].subsampling_x;
1373 const int ss_y = xd->
plane[1].subsampling_y;
1378 if (ss_x && bw < mi_size_wide[BLOCK_8X8])
1380 if (ss_y && bh < mi_size_high[BLOCK_8X8])
1394 const int chroma_ref = ((mi_row & 0x01) || !(bh & 0x01) || !ss_y) &&
1395 ((mi_col & 0x01) || !(bw & 0x01) || !ss_x);
1403 &xd->
mi[-(mi_row & ss_y) * xd->
mi_stride - (mi_col & ss_x)];
1433static inline aom_cdf_prob *get_y_mode_cdf(FRAME_CONTEXT *tile_ctx,
1436 const PREDICTION_MODE above = av1_above_block_mode(above_mi);
1437 const PREDICTION_MODE left = av1_left_block_mode(left_mi);
1438 const int above_ctx = intra_mode_context[above];
1439 const int left_ctx = intra_mode_context[left];
1440 return tile_ctx->kf_y_cdf[above_ctx][left_ctx];
1443static inline void update_partition_context(MACROBLOCKD *xd,
int mi_row,
1444 int mi_col, BLOCK_SIZE subsize,
1447 PARTITION_CONTEXT *
const left_ctx =
1450 const int bw = mi_size_wide[bsize];
1451 const int bh = mi_size_high[bsize];
1452 memset(above_ctx, partition_context_lookup[subsize].above, bw);
1453 memset(left_ctx, partition_context_lookup[subsize].left, bh);
1456static inline int is_chroma_reference(
int mi_row,
int mi_col, BLOCK_SIZE bsize,
1457 int subsampling_x,
int subsampling_y) {
1458 assert(bsize < BLOCK_SIZES_ALL);
1459 const int bw = mi_size_wide[bsize];
1460 const int bh = mi_size_high[bsize];
1461 int ref_pos = ((mi_row & 0x01) || !(bh & 0x01) || !subsampling_y) &&
1462 ((mi_col & 0x01) || !(bw & 0x01) || !subsampling_x);
1466static inline aom_cdf_prob cdf_element_prob(
const aom_cdf_prob *cdf,
1468 assert(cdf != NULL);
1469 return (element > 0 ? cdf[element - 1] : CDF_PROB_TOP) - cdf[element];
1472static inline void partition_gather_horz_alike(aom_cdf_prob *out,
1473 const aom_cdf_prob *
const in,
1476 out[0] = CDF_PROB_TOP;
1477 out[0] -= cdf_element_prob(in, PARTITION_HORZ);
1478 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1479 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1480 out[0] -= cdf_element_prob(in, PARTITION_HORZ_B);
1481 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1482 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_HORZ_4);
1483 out[0] = AOM_ICDF(out[0]);
1484 out[1] = AOM_ICDF(CDF_PROB_TOP);
1487static inline void partition_gather_vert_alike(aom_cdf_prob *out,
1488 const aom_cdf_prob *
const in,
1491 out[0] = CDF_PROB_TOP;
1492 out[0] -= cdf_element_prob(in, PARTITION_VERT);
1493 out[0] -= cdf_element_prob(in, PARTITION_SPLIT);
1494 out[0] -= cdf_element_prob(in, PARTITION_HORZ_A);
1495 out[0] -= cdf_element_prob(in, PARTITION_VERT_A);
1496 out[0] -= cdf_element_prob(in, PARTITION_VERT_B);
1497 if (bsize != BLOCK_128X128) out[0] -= cdf_element_prob(in, PARTITION_VERT_4);
1498 out[0] = AOM_ICDF(out[0]);
1499 out[1] = AOM_ICDF(CDF_PROB_TOP);
1502static inline void update_ext_partition_context(MACROBLOCKD *xd,
int mi_row,
1503 int mi_col, BLOCK_SIZE subsize,
1505 PARTITION_TYPE partition) {
1506 if (bsize >= BLOCK_8X8) {
1507 const int hbs = mi_size_wide[bsize] / 2;
1508 BLOCK_SIZE bsize2 = get_partition_subsize(bsize, PARTITION_SPLIT);
1509 switch (partition) {
1510 case PARTITION_SPLIT:
1511 if (bsize != BLOCK_8X8)
break;
1512 AOM_FALLTHROUGH_INTENDED;
1513 case PARTITION_NONE:
1514 case PARTITION_HORZ:
1515 case PARTITION_VERT:
1516 case PARTITION_HORZ_4:
1517 case PARTITION_VERT_4:
1518 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1520 case PARTITION_HORZ_A:
1521 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1522 update_partition_context(xd, mi_row + hbs, mi_col, subsize, subsize);
1524 case PARTITION_HORZ_B:
1525 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1526 update_partition_context(xd, mi_row + hbs, mi_col, bsize2, subsize);
1528 case PARTITION_VERT_A:
1529 update_partition_context(xd, mi_row, mi_col, bsize2, subsize);
1530 update_partition_context(xd, mi_row, mi_col + hbs, subsize, subsize);
1532 case PARTITION_VERT_B:
1533 update_partition_context(xd, mi_row, mi_col, subsize, subsize);
1534 update_partition_context(xd, mi_row, mi_col + hbs, bsize2, subsize);
1536 default: assert(0 &&
"Invalid partition type");
1541static inline int partition_plane_context(
const MACROBLOCKD *xd,
int mi_row,
1542 int mi_col, BLOCK_SIZE bsize) {
1544 const PARTITION_CONTEXT *left_ctx =
1547 const int bsl = mi_size_wide_log2[bsize] - mi_size_wide_log2[BLOCK_8X8];
1548 int above = (*above_ctx >> bsl) & 1, left = (*left_ctx >> bsl) & 1;
1550 assert(mi_size_wide_log2[bsize] == mi_size_high_log2[bsize]);
1553 return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
1558static inline int partition_cdf_length(BLOCK_SIZE bsize) {
1559 if (bsize <= BLOCK_8X8)
1560 return PARTITION_TYPES;
1561 else if (bsize == BLOCK_128X128)
1562 return EXT_PARTITION_TYPES - 2;
1564 return EXT_PARTITION_TYPES;
1567static inline int max_block_wide(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1569 assert(bsize < BLOCK_SIZES_ALL);
1570 int max_blocks_wide = block_size_wide[bsize];
1573 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1578 return max_blocks_wide >> MI_SIZE_LOG2;
1581static inline int max_block_high(
const MACROBLOCKD *xd, BLOCK_SIZE bsize,
1583 int max_blocks_high = block_size_high[bsize];
1586 const struct macroblockd_plane *
const pd = &xd->
plane[plane];
1591 return max_blocks_high >> MI_SIZE_LOG2;
1594static inline void av1_zero_above_context(AV1_COMMON *
const cm,
1595 const MACROBLOCKD *xd,
1596 int mi_col_start,
int mi_col_end,
1597 const int tile_row) {
1598 const SequenceHeader *
const seq_params = cm->
seq_params;
1599 const int num_planes = av1_num_planes(cm);
1600 const int width = mi_col_end - mi_col_start;
1601 const int aligned_width =
1602 ALIGN_POWER_OF_TWO(width, seq_params->mib_size_log2);
1603 const int offset_y = mi_col_start;
1604 const int width_y = aligned_width;
1605 const int offset_uv = offset_y >> seq_params->subsampling_x;
1606 const int width_uv = width_y >> seq_params->subsampling_x;
1609 av1_zero_array(above_contexts->
entropy[0][tile_row] + offset_y, width_y);
1610 if (num_planes > 1) {
1611 if (above_contexts->
entropy[1][tile_row] &&
1612 above_contexts->
entropy[2][tile_row]) {
1613 av1_zero_array(above_contexts->
entropy[1][tile_row] + offset_uv,
1615 av1_zero_array(above_contexts->
entropy[2][tile_row] + offset_uv,
1619 "Invalid value of planes");
1623 av1_zero_array(above_contexts->
partition[tile_row] + mi_col_start,
1626 memset(above_contexts->
txfm[tile_row] + mi_col_start,
1627 tx_size_wide[TX_SIZES_LARGEST], aligned_width *
sizeof(TXFM_CONTEXT));
1630static inline void av1_zero_left_context(MACROBLOCKD *
const xd) {
1638static inline void set_txfm_ctx(TXFM_CONTEXT *txfm_ctx, uint8_t txs,
int len) {
1640 for (i = 0; i < len; ++i) txfm_ctx[i] = txs;
1643static inline void set_txfm_ctxs(TX_SIZE tx_size,
int n4_w,
int n4_h,
int skip,
1644 const MACROBLOCKD *xd) {
1645 uint8_t bw = tx_size_wide[tx_size];
1646 uint8_t bh = tx_size_high[tx_size];
1649 bw = n4_w * MI_SIZE;
1650 bh = n4_h * MI_SIZE;
1658 int mi_row,
int mi_col) {
1659 return mi_row * mi_params->
mi_stride + mi_col;
1663 int mi_row,
int mi_col) {
1664 const int mi_alloc_size_1d = mi_size_wide[mi_params->
mi_alloc_bsize];
1665 const int mi_alloc_row = mi_row / mi_alloc_size_1d;
1666 const int mi_alloc_col = mi_col / mi_alloc_size_1d;
1673 MACROBLOCKD *
const xd,
int mi_row,
1676 const int mi_grid_idx = get_mi_grid_idx(mi_params, mi_row, mi_col);
1677 const int mi_alloc_idx = get_alloc_mi_idx(mi_params, mi_row, mi_col);
1686static inline void txfm_partition_update(TXFM_CONTEXT *above_ctx,
1687 TXFM_CONTEXT *left_ctx,
1688 TX_SIZE tx_size, TX_SIZE txb_size) {
1689 BLOCK_SIZE bsize = txsize_to_bsize[txb_size];
1690 int bh = mi_size_high[bsize];
1691 int bw = mi_size_wide[bsize];
1692 uint8_t txw = tx_size_wide[tx_size];
1693 uint8_t txh = tx_size_high[tx_size];
1695 for (i = 0; i < bh; ++i) left_ctx[i] = txh;
1696 for (i = 0; i < bw; ++i) above_ctx[i] = txw;
1699static inline TX_SIZE get_sqr_tx_size(
int tx_dim) {
1702 case 64:
return TX_64X64;
break;
1703 case 32:
return TX_32X32;
break;
1704 case 16:
return TX_16X16;
break;
1705 case 8:
return TX_8X8;
break;
1706 default:
return TX_4X4;
1710static inline TX_SIZE get_tx_size(
int width,
int height) {
1711 if (width == height) {
1712 return get_sqr_tx_size(width);
1714 if (width < height) {
1715 if (width + width == height) {
1717 case 4:
return TX_4X8;
break;
1718 case 8:
return TX_8X16;
break;
1719 case 16:
return TX_16X32;
break;
1720 case 32:
return TX_32X64;
break;
1724 case 4:
return TX_4X16;
break;
1725 case 8:
return TX_8X32;
break;
1726 case 16:
return TX_16X64;
break;
1730 if (height + height == width) {
1732 case 4:
return TX_8X4;
break;
1733 case 8:
return TX_16X8;
break;
1734 case 16:
return TX_32X16;
break;
1735 case 32:
return TX_64X32;
break;
1739 case 4:
return TX_16X4;
break;
1740 case 8:
return TX_32X8;
break;
1741 case 16:
return TX_64X16;
break;
1749static inline int txfm_partition_context(
const TXFM_CONTEXT *
const above_ctx,
1750 const TXFM_CONTEXT *
const left_ctx,
1751 BLOCK_SIZE bsize, TX_SIZE tx_size) {
1752 const uint8_t txw = tx_size_wide[tx_size];
1753 const uint8_t txh = tx_size_high[tx_size];
1754 const int above = *above_ctx < txw;
1755 const int left = *left_ctx < txh;
1756 int category = TXFM_PARTITION_CONTEXTS;
1759 if (tx_size <= TX_4X4)
return 0;
1761 TX_SIZE max_tx_size =
1762 get_sqr_tx_size(AOMMAX(block_size_wide[bsize], block_size_high[bsize]));
1764 if (max_tx_size >= TX_8X8) {
1766 (txsize_sqr_up_map[tx_size] != max_tx_size && max_tx_size > TX_8X8) +
1767 (TX_SIZES - 1 - max_tx_size) * 2;
1769 assert(category != TXFM_PARTITION_CONTEXTS);
1770 return category * 3 + above + left;
1775static inline PARTITION_TYPE get_partition(
const AV1_COMMON *
const cm,
1776 int mi_row,
int mi_col,
1779 if (mi_row >= mi_params->
mi_rows || mi_col >= mi_params->
mi_cols)
1780 return PARTITION_INVALID;
1782 const int offset = mi_row * mi_params->
mi_stride + mi_col;
1784 const BLOCK_SIZE subsize = mi[0]->
bsize;
1786 assert(bsize < BLOCK_SIZES_ALL);
1788 if (subsize == bsize)
return PARTITION_NONE;
1790 const int bhigh = mi_size_high[bsize];
1791 const int bwide = mi_size_wide[bsize];
1792 const int sshigh = mi_size_high[subsize];
1793 const int sswide = mi_size_wide[subsize];
1795 if (bsize > BLOCK_8X8 && mi_row + bwide / 2 < mi_params->
mi_rows &&
1796 mi_col + bhigh / 2 < mi_params->
mi_cols) {
1802 if (sswide == bwide) {
1806 if (sshigh * 4 == bhigh)
return PARTITION_HORZ_4;
1807 assert(sshigh * 2 == bhigh);
1809 if (mbmi_below->
bsize == subsize)
1810 return PARTITION_HORZ;
1812 return PARTITION_HORZ_B;
1813 }
else if (sshigh == bhigh) {
1817 if (sswide * 4 == bwide)
return PARTITION_VERT_4;
1818 assert(sswide * 2 == bwide);
1820 if (mbmi_right->
bsize == subsize)
1821 return PARTITION_VERT;
1823 return PARTITION_VERT_B;
1832 if (sswide * 2 != bwide || sshigh * 2 != bhigh)
return PARTITION_SPLIT;
1834 if (mi_size_wide[mbmi_below->
bsize] == bwide)
return PARTITION_HORZ_A;
1835 if (mi_size_high[mbmi_right->
bsize] == bhigh)
return PARTITION_VERT_A;
1837 return PARTITION_SPLIT;
1840 const int vert_split = sswide < bwide;
1841 const int horz_split = sshigh < bhigh;
1842 const int split_idx = (vert_split << 1) | horz_split;
1843 assert(split_idx != 0);
1845 static const PARTITION_TYPE base_partitions[4] = {
1846 PARTITION_INVALID, PARTITION_HORZ, PARTITION_VERT, PARTITION_SPLIT
1849 return base_partitions[split_idx];
1852static inline void set_sb_size(SequenceHeader *
const seq_params,
1853 BLOCK_SIZE sb_size) {
1854 seq_params->sb_size = sb_size;
1855 seq_params->mib_size = mi_size_wide[seq_params->sb_size];
1856 seq_params->mib_size_log2 = mi_size_wide_log2[seq_params->sb_size];
1862static inline int is_coded_lossless(
const AV1_COMMON *cm,
1863 const MACROBLOCKD *xd) {
1864 int coded_lossless = 1;
1865 if (cm->
seg.enabled) {
1866 for (
int i = 0; i < MAX_SEGMENTS; ++i) {
1875 return coded_lossless;
1878static inline int is_valid_seq_level_idx(AV1_LEVEL seq_level_idx) {
1879 return seq_level_idx == SEQ_LEVEL_MAX ||
1880 (seq_level_idx < SEQ_LEVELS &&
1882 seq_level_idx != SEQ_LEVEL_2_2 && seq_level_idx != SEQ_LEVEL_2_3 &&
1883 seq_level_idx != SEQ_LEVEL_3_2 && seq_level_idx != SEQ_LEVEL_3_3 &&
1884 seq_level_idx != SEQ_LEVEL_4_2 && seq_level_idx != SEQ_LEVEL_4_3
1886 && seq_level_idx != SEQ_LEVEL_7_0 && seq_level_idx != SEQ_LEVEL_7_1 &&
1887 seq_level_idx != SEQ_LEVEL_7_2 && seq_level_idx != SEQ_LEVEL_7_3 &&
1888 seq_level_idx != SEQ_LEVEL_8_0 && seq_level_idx != SEQ_LEVEL_8_1 &&
1889 seq_level_idx != SEQ_LEVEL_8_2 && seq_level_idx != SEQ_LEVEL_8_3
int(* aom_get_frame_buffer_cb_fn_t)(void *priv, size_t min_size, aom_codec_frame_buffer_t *fb)
get frame buffer callback prototype
Definition aom_frame_buffer.h:64
int(* aom_release_frame_buffer_cb_fn_t)(void *priv, aom_codec_frame_buffer_t *fb)
release frame buffer callback prototype
Definition aom_frame_buffer.h:77
struct aom_codec_frame_buffer aom_codec_frame_buffer_t
External frame buffer.
#define AOM_PLANE_U
Definition aom_image.h:240
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
enum aom_transfer_characteristics aom_transfer_characteristics_t
List of supported transfer functions.
enum aom_color_primaries aom_color_primaries_t
List of supported color primaries.
enum aom_matrix_coefficients aom_matrix_coefficients_t
List of supported matrix coefficients.
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
@ AOM_CODEC_CORRUPT_FRAME
The coded data for this stream is corrupt or incomplete.
Definition aom_codec.h:195
Top level common structure used by both encoder and decoder.
Definition av1_common_int.h:766
uint8_t * last_frame_seg_map
Definition av1_common_int.h:948
RestorationInfo rst_info[3]
Definition av1_common_int.h:962
WarpedMotionParams global_motion[REF_FRAMES]
Definition av1_common_int.h:986
int superres_upscaled_width
Definition av1_common_int.h:815
int8_t ref_frame_side[REF_FRAMES]
Definition av1_common_int.h:1053
struct scale_factors ref_scale_factors[REF_FRAMES]
Definition av1_common_int.h:885
RefCntBuffer * prev_frame
Definition av1_common_int.h:842
FRAME_CONTEXT * default_frame_context
Definition av1_common_int.h:1003
int ref_frame_id[REF_FRAMES]
Definition av1_common_int.h:1028
int superres_upscaled_height
Definition av1_common_int.h:816
DeltaQInfo delta_q_info
Definition av1_common_int.h:981
SequenceHeader * seq_params
Definition av1_common_int.h:992
int width
Definition av1_common_int.h:791
RefCntBuffer * cur_frame
Definition av1_common_int.h:848
CdefInfo cdef_info
Definition av1_common_int.h:971
loop_filter_info_n lf_info
Definition av1_common_int.h:954
CurrentFrame current_frame
Definition av1_common_int.h:770
int remapped_ref_idx[REF_FRAMES]
Definition av1_common_int.h:870
RestorationLineBuffers * rlbs
Definition av1_common_int.h:964
aom_film_grain_t film_grain_params
Definition av1_common_int.h:976
int show_existing_frame
Definition av1_common_int.h:916
int temporal_layer_id
Definition av1_common_int.h:1059
struct aom_internal_error_info * error
Definition av1_common_int.h:774
int showable_frame
Definition av1_common_int.h:909
int tpl_mvs_mem_size
Definition av1_common_int.h:1042
uint32_t frame_presentation_time
Definition av1_common_int.h:837
uint32_t buffer_removal_times[(8 *4)+1]
Definition av1_common_int.h:831
struct loopfilter lf
Definition av1_common_int.h:955
int spatial_layer_id
Definition av1_common_int.h:1065
FeatureFlags features
Definition av1_common_int.h:921
struct scale_factors sf_identity
Definition av1_common_int.h:877
YV12_BUFFER_CONFIG rst_frame
Definition av1_common_int.h:965
CommonModeInfoParams mi_params
Definition av1_common_int.h:926
uint8_t superres_scale_denominator
Definition av1_common_int.h:823
int show_frame
Definition av1_common_int.h:901
struct segmentation seg
Definition av1_common_int.h:943
CommonQuantParams quant_params
Definition av1_common_int.h:938
TPL_MV_REF * tpl_mvs
Definition av1_common_int.h:1038
int current_frame_id
Definition av1_common_int.h:1027
int32_t * rst_tmpbuf
Definition av1_common_int.h:963
RefCntBuffer * ref_frame_map[REF_FRAMES]
Definition av1_common_int.h:894
CommonContexts above_contexts
Definition av1_common_int.h:1021
CommonTileParams tiles
Definition av1_common_int.h:1008
BufferPool * buffer_pool
Definition av1_common_int.h:1013
int ref_frame_sign_bias[REF_FRAMES]
Definition av1_common_int.h:1047
FRAME_CONTEXT * fc
Definition av1_common_int.h:997
int height
Definition av1_common_int.h:792
int render_width
Definition av1_common_int.h:802
int render_height
Definition av1_common_int.h:803
Parameters related to CDEF.
Definition av1_common_int.h:203
size_t allocated_linebuf_size[3]
CDEF top and bottom line buffer sizes.
Definition av1_common_int.h:213
int cdef_bits
Number of CDEF strength values in bits.
Definition av1_common_int.h:225
int allocated_mi_rows
Number of rows in the frame in 4 pixel.
Definition av1_common_int.h:227
uint16_t * linebuf[3]
CDEF top & bottom line buffer.
Definition av1_common_int.h:207
int allocated_num_workers
Number of CDEF workers.
Definition av1_common_int.h:229
int cdef_uv_strengths[16]
CDEF strength values for chroma.
Definition av1_common_int.h:223
uint16_t * colbuf[3]
CDEF column line buffer.
Definition av1_common_int.h:205
size_t allocated_srcbuf_size
CDEF intermediate buffer size.
Definition av1_common_int.h:215
int cdef_strengths[16]
CDEF strength values for luma.
Definition av1_common_int.h:221
size_t allocated_colbuf_size[3]
CDEF column line buffer sizes.
Definition av1_common_int.h:211
int nb_cdef_strengths
Number of CDEF strength values.
Definition av1_common_int.h:219
int cdef_damping
CDEF damping factor.
Definition av1_common_int.h:217
uint16_t * srcbuf
CDEF intermediate buffer.
Definition av1_common_int.h:209
Contexts used for transmitting various symbols in the bitstream.
Definition av1_common_int.h:729
PARTITION_CONTEXT ** partition
Definition av1_common_int.h:734
int num_planes
Definition av1_common_int.h:758
ENTROPY_CONTEXT ** entropy[3]
Definition av1_common_int.h:744
int num_tile_rows
Definition av1_common_int.h:759
int num_mi_cols
Definition av1_common_int.h:760
TXFM_CONTEXT ** txfm
Definition av1_common_int.h:752
Params related to MB_MODE_INFO arrays and related info.
Definition av1_common_int.h:511
int mb_cols
Definition av1_common_int.h:521
MB_MODE_INFO * mi_alloc
Definition av1_common_int.h:545
int mi_rows
Definition av1_common_int.h:532
void(* setup_mi)(struct CommonModeInfoParams *mi_params)
Definition av1_common_int.h:600
void(* free_mi)(struct CommonModeInfoParams *mi_params)
Definition av1_common_int.h:595
int mi_cols
Definition av1_common_int.h:537
int mi_alloc_size
Definition av1_common_int.h:549
void(* set_mb_mi)(struct CommonModeInfoParams *mi_params, int width, int height, BLOCK_SIZE min_partition_size)
Definition av1_common_int.h:610
int MBs
Definition av1_common_int.h:526
TX_TYPE * tx_type_map
Definition av1_common_int.h:585
int mi_alloc_stride
Definition av1_common_int.h:553
int mi_grid_size
Definition av1_common_int.h:573
int mi_stride
Definition av1_common_int.h:577
int mb_rows
Definition av1_common_int.h:516
MB_MODE_INFO ** mi_grid_base
Definition av1_common_int.h:569
BLOCK_SIZE mi_alloc_bsize
Definition av1_common_int.h:560
Parameters related to quantization at the frame level.
Definition av1_common_int.h:619
int u_ac_delta_q
Definition av1_common_int.h:649
const qm_val_t * u_iqmatrix[8][TX_SIZES_ALL]
Definition av1_common_int.h:698
int qmatrix_level_v
Definition av1_common_int.h:721
const qm_val_t * giqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition av1_common_int.h:680
int16_t u_dequant_QTX[8][2]
Definition av1_common_int.h:669
const qm_val_t * y_iqmatrix[8][TX_SIZES_ALL]
Definition av1_common_int.h:694
int qmatrix_level_y
Definition av1_common_int.h:719
int v_ac_delta_q
Definition av1_common_int.h:654
bool using_qmatrix
Definition av1_common_int.h:712
int u_dc_delta_q
Definition av1_common_int.h:639
int qmatrix_level_u
Definition av1_common_int.h:720
int base_qindex
Definition av1_common_int.h:623
int16_t v_dequant_QTX[8][2]
Definition av1_common_int.h:670
const qm_val_t * v_iqmatrix[8][TX_SIZES_ALL]
Definition av1_common_int.h:702
int sharpness
Definition av1_common_int.h:628
int16_t y_dequant_QTX[8][2]
Definition av1_common_int.h:668
int v_dc_delta_q
Definition av1_common_int.h:643
int y_dc_delta_q
Definition av1_common_int.h:634
const qm_val_t * gqmatrix[(1<< 4)][3][TX_SIZES_ALL]
Definition av1_common_int.h:684
Params related to tiles.
Definition av1_common_int.h:437
int uniform_spacing
Definition av1_common_int.h:453
int max_width_sb
Definition av1_common_int.h:440
int log2_rows
Definition av1_common_int.h:460
int min_log2_rows
Definition av1_common_int.h:472
int width
Definition av1_common_int.h:461
int max_log2_rows
Definition av1_common_int.h:480
int row_start_sb[MAX_TILE_ROWS+1]
Definition av1_common_int.h:494
int cols
Definition av1_common_int.h:438
int max_height_sb
Definition av1_common_int.h:441
unsigned int large_scale
Definition av1_common_int.h:498
unsigned int single_tile_decoding
Definition av1_common_int.h:504
int max_log2_cols
Definition av1_common_int.h:476
int log2_cols
Definition av1_common_int.h:459
int min_log2
Definition av1_common_int.h:484
int rows
Definition av1_common_int.h:439
int min_inner_width
Definition av1_common_int.h:446
int min_log2_cols
Definition av1_common_int.h:468
int col_start_sb[MAX_TILE_COLS+1]
Definition av1_common_int.h:489
int height
Definition av1_common_int.h:462
Frame level features.
Definition av1_common_int.h:368
InterpFilter interp_filter
Definition av1_common_int.h:417
bool allow_ref_frame_mvs
Definition av1_common_int.h:391
bool allow_warped_motion
Definition av1_common_int.h:387
bool allow_screen_content_tools
Definition av1_common_int.h:385
bool switchable_motion_mode
Definition av1_common_int.h:415
TX_MODE tx_mode
Definition av1_common_int.h:416
bool reduced_tx_set_used
Definition av1_common_int.h:404
bool allow_intrabc
Definition av1_common_int.h:386
int byte_alignment
Definition av1_common_int.h:426
bool coded_lossless
Definition av1_common_int.h:395
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context
Definition av1_common_int.h:431
bool error_resilient_mode
Definition av1_common_int.h:410
int primary_ref_frame
Definition av1_common_int.h:422
bool disable_cdf_update
Definition av1_common_int.h:372
bool allow_high_precision_mv
Definition av1_common_int.h:377
bool cur_frame_force_integer_mv
Definition av1_common_int.h:381
bool all_lossless
Definition av1_common_int.h:399
Stores the prediction/txfm mode of the current coding block.
Definition blockd.h:222
BLOCK_SIZE bsize
The block size of the current coding block.
Definition blockd.h:228
Parameters related to Restoration Info.
Definition restoration.h:246
bool left_available
Definition blockd.h:626
uint8_t * tx_type_map
Definition blockd.h:666
int mb_to_bottom_edge
Definition blockd.h:680
TXFM_CONTEXT * left_txfm_context
Definition blockd.h:740
struct macroblockd_plane plane[3]
Definition blockd.h:606
int mb_to_top_edge
Definition blockd.h:679
int mb_to_right_edge
Definition blockd.h:678
bool up_available
Definition blockd.h:622
MB_MODE_INFO * above_mbmi
Definition blockd.h:645
bool chroma_up_available
Definition blockd.h:630
TXFM_CONTEXT * above_txfm_context
Definition blockd.h:733
bool chroma_left_available
Definition blockd.h:634
PARTITION_CONTEXT * above_partition_context
Definition blockd.h:718
MB_MODE_INFO * chroma_left_mbmi
Definition blockd.h:652
TXFM_CONTEXT left_txfm_context_buffer[MAX_MIB_SIZE]
Definition blockd.h:747
int tx_type_map_stride
Definition blockd.h:671
MB_MODE_INFO * chroma_above_mbmi
Definition blockd.h:659
int mi_row
Definition blockd.h:575
int mi_stride
Definition blockd.h:582
bool is_last_vertical_rect
Definition blockd.h:787
bool is_first_horizontal_rect
Definition blockd.h:792
uint8_t width
Definition blockd.h:765
struct aom_internal_error_info * error_info
Definition blockd.h:838
CFL_CTX cfl
Definition blockd.h:894
int lossless[8]
Definition blockd.h:817
ENTROPY_CONTEXT left_entropy_context[3][MAX_MIB_SIZE]
Definition blockd.h:710
ENTROPY_CONTEXT * above_entropy_context[3]
Definition blockd.h:703
MB_MODE_INFO ** mi
Definition blockd.h:617
uint8_t height
Definition blockd.h:766
MB_MODE_INFO * left_mbmi
Definition blockd.h:640
PARTITION_CONTEXT left_partition_context[MAX_MIB_SIZE]
Definition blockd.h:725
bool is_chroma_ref
Definition blockd.h:601
int mi_col
Definition blockd.h:576
int mb_to_left_edge
Definition blockd.h:677